package com.openbravo.pos.printer.ticket;

import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import org.krysalis.barcode4j.BarcodeDimension;
import org.krysalis.barcode4j.HumanReadablePlacement;
import org.krysalis.barcode4j.impl.AbstractBarcodeBean;
import org.krysalis.barcode4j.impl.code128.Code128Bean;
import org.krysalis.barcode4j.impl.upcean.EAN13Bean;
import org.krysalis.barcode4j.output.java2d.Java2DCanvasProvider;

public class PrintItemBarcode
  implements PrintItem
{
  protected AbstractBarcodeBean m_barcode;
  protected String m_sCode;
  protected int m_iWidth;
  protected int m_iHeight;
  protected double scale;

  public PrintItemBarcode(String paramString1, String paramString2, String paramString3, double paramDouble)
  {
    this.m_sCode = paramString3;
    this.scale = paramDouble;
    if ("CODE128".equals(paramString1))
      this.m_barcode = new Code128Bean();
    else
      this.m_barcode = new EAN13Bean();
    if (this.m_barcode != null)
    {
      this.m_barcode.setModuleWidth(1.0D);
      this.m_barcode.setBarHeight(40.0D);
      this.m_barcode.setFontSize(10.0D);
      this.m_barcode.setQuietZone(10.0D);
      this.m_barcode.doQuietZone(true);
      if ("none".equals(paramString2))
        this.m_barcode.setMsgPosition(HumanReadablePlacement.HRP_NONE);
      else
        this.m_barcode.setMsgPosition(HumanReadablePlacement.HRP_BOTTOM);
      BarcodeDimension localBarcodeDimension = this.m_barcode.calcDimensions(this.m_sCode);
      this.m_iWidth = (int)localBarcodeDimension.getWidth(0);
      this.m_iHeight = (int)localBarcodeDimension.getHeight(0);
    }
  }

  public void draw(Graphics2D paramGraphics2D, int paramInt1, int paramInt2, int paramInt3)
  {
    if (this.m_barcode != null)
    {
      Graphics2D localGraphics2D = paramGraphics2D;
      AffineTransform localAffineTransform = localGraphics2D.getTransform();
      localGraphics2D.translate(paramInt1 - 10 + (paramInt3 - (int)(this.m_iWidth * this.scale)) / 2, paramInt2 + 10);
      localGraphics2D.scale(this.scale, this.scale);
      try
      {
        this.m_barcode.generateBarcode(new Java2DCanvasProvider(localGraphics2D, 0), this.m_sCode);
      }
      catch (IllegalArgumentException localIllegalArgumentException)
      {
        localGraphics2D.drawRect(0, 0, this.m_iWidth, this.m_iHeight);
        localGraphics2D.drawLine(0, 0, this.m_iWidth, this.m_iHeight);
        localGraphics2D.drawLine(this.m_iWidth, 0, 0, this.m_iHeight);
      }
      localGraphics2D.setTransform(localAffineTransform);
    }
  }

  public int getHeight()
  {
    return (int)(this.m_iHeight * this.scale) + 20;
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.printer.ticket.PrintItemBarcode
 * JD-Core Version:    0.6.0
 */